#ifndef DOWNLOADMANAGER_H
#define DOWNLOADMANAGER_H

#include <QObject>
#include <QNetworkReply>

class QStringList;
class QNetworkAccessManager;

class DownloadManager: public QObject
{
    Q_OBJECT

public:
    DownloadManager(QObject* parent);

    // API
    int getProductList(QStringList& products);
    int getProduct(QString account,
                   QString productId,
                   QString* ticket = NULL);
    bool isNeedToBuy(QByteArray& response);

signals:
    void productListComplete();
    void productComplete(QByteArray* buf);

private slots:
    void replyFinished(QNetworkReply* reply);
    void replyError(QNetworkReply::NetworkError error);

private:
    void handleProduct(QByteArray& buf);
    void handleProductList(QByteArray& buf);

private:
    //data
    enum ComponentState{
        State_IDLE,
        State_GETPRODUCTLIST,
        State_GETPRODUCT
    };
    QNetworkAccessManager   *manager;
    ComponentState          state;
    QStringList             *productList; //does not own
};

#endif // DOWNLOADMANAGER_H
